package cn.yunhe.servlet;

import cn.yunhe.entity.Admin;
import cn.yunhe.util.JsonUtil;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/JsonTestServlet")
public class JsonTestServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Admin admin = new Admin("jack", "123");
        Admin admin2 = new Admin("rose", "222");
        Admin admin3 = new Admin("tom", "333");
        Admin admin4 = new Admin("jerry", "444");

        List<Admin> list = new ArrayList<Admin>();
        list.add(admin);
        list.add(admin2);
        list.add(admin3);
        list.add(admin4);

        Map<String, Object> maps = new HashMap<String, Object>();
        maps.put("list",list);
        maps.put("pageIndex",2);
        maps.put("totalPages",10);

        JsonUtil.getJson(response, maps);


    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
